
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




package strutsitem;




import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import jpa.entities.Property;
import jpa.sessions.PropertyFacade;



/**

 *

 * @author JAVA

 */

public class SearchForRentalPayingGuest extends ActionCommon {
    PropertyFacade propertyFacade = lookupPropertyFacadeBean();
    double rentMax,rentMin,depositMax,depositMin;
    private String city;

    public double getDepositMax() {
        return depositMax;
    }

    public void setDepositMax(double maxDeposit) {
        this.depositMax = maxDeposit;
    }

    public double getRentMax() {
        return rentMax;
    }

    public void setRentMax(double maxRent) {
        this.rentMax = maxRent;
    }

    public double getDepositMin() {
        return depositMin;
    }

    public void setDepositMin(double minDeposit) {
        this.depositMin = minDeposit;
    }

    public double getRentMin() {
        return rentMin;
    }

    public void setRentMin(double minRent) {
        this.rentMin = minRent;
    }

    public PropertyFacade getPropertyFacade() {
        return propertyFacade;
    }

    public void setPropertyFacade(PropertyFacade propertyFacade) {
        this.propertyFacade = propertyFacade;
    }
    public SearchForRentalPayingGuest() {
        
    }

    @Override
    public String execute() throws Exception {
        Collection<Property> properties=propertyFacade.findByAccomodation(depositMax,depositMin,rentMax,rentMin,city);
        System.out.println("city :"+getCity()+"-maxRent"+getRentMax()+"-num Property:"+properties.size());
        session.setAttribute("properties",properties);
        return "DisplayResult";

    }


    private PropertyFacade lookupPropertyFacadeBean() {
        try {
            Context c = new InitialContext();
            return (PropertyFacade) c.lookup("java:global/MySweetHome/PropertyFacade!jpa.sessions.PropertyFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    /**
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * @param city the city to set
     */
    public void setCity(String city) {
        this.city = city;
    }






}